package com.itheima.manager.web;

import com.itheima.manager.pojo.Contact;
import com.itheima.manager.service.ISelectByNameService;
import com.itheima.manager.service.imp.SelectByNameServiceImp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(name = "SelectLinkServlet", value = "/SelectLinkServlet")
public class SelectLinkServlet extends HttpServlet {
    private ISelectByNameService  iSelectByNameService = new SelectByNameServiceImp();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("name");
        String min = request.getParameter("min");
        String max = request.getParameter("max");



        Map<String,String> map = new HashMap<>();
        map.put("name",name);
        map.put("min",min);
        map.put("max",max);


        List<Contact> contacts = iSelectByNameService.selectLink(map);

        request.setAttribute("contacts",contacts);
        request.getRequestDispatcher("list.jsp").forward(request,response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
               doGet(request,response);
    }
}
